package analisis.matrizContingencia;

import java.util.List;

/**
 * @file JaccardSimilarity.java
 * @author Juan Humanes Ferrer
 * @date 14-Marzo-2014
 *
 */
public final class JaccardSimilarity implements IMedida {

    private double jaccardSimilarity;

    public JaccardSimilarity() {
        setJaccardSimilarity(0.0);
    }

    /**
     * Método que retorna el jaccardSimilarity
     *
     * @return jaccardSimilarity
     */
    public double getJaccardSimilarity() {
        return jaccardSimilarity;
    }

    /**
     * Métodod que modifica el valor de jaccardSimilarity
     *
     * @param jaccardSimilarity
     */
    public void setJaccardSimilarity(double jaccardSimilarity) {
        this.jaccardSimilarity = jaccardSimilarity;
    }

    /**
     * Método que calcula el meanError
     *
     * @param tp
     * @param tn
     * @param fp
     * @param fn
     * @param valoresMedidas
     */
    @Override
    public void calculaMedida(double tp, double tn, double fp, double fn,List<IMedida> valoresMedidas) {
        double result = Double.POSITIVE_INFINITY;

        if (tp != 0.0 && fn != 0.0 && fp != 0.0) {
            result = tp / (tp + fn + fp);
        }

        setJaccardSimilarity(result);
    }

    @Override
    public Double verValor() {
        return getJaccardSimilarity();
    }

}
